layui.use(['form','jquery'], function() {
    var form = layui.form,
        $ = layui.jquery,
        layer = layui.layer;


    /*
        从后台加载区域列表
    */
    $(document).ready(function () {
        var brokerBuildingId = window.location.search.substr(4);
        $.post('/broker-building/getAreaId',{"id":brokerBuildingId},function (info) {
            var tenancyAreaId = info.data.tenancyAreaId;
            var saleAreaId = info.data.saleAreaId;

            //租赁区域下拉框
            if(tenancyAreaId != "null"){
                //发送post请求，获取所有区域信息,并自动显示已选区域
                $.post('/tenancy-area/getAreaIdAndName', function (info) {
                    //遍历循环信息
                    info.data.forEach(function (area) {
                        $("#tenancyAreaName").append("<option value=" + area.tenancyAreaId + ">" + area.tenancyAreaName + "</option>");
                        form.render('select');
                        $("#tenancyAreaName").val(tenancyAreaId);
                        form.render('select');
                    })
                });
            }else {
                //发送post请求，获取所有区域信息
                $.post('/tenancy-area/getAreaIdAndName', function (info) {
                    //遍历循环信息
                    info.data.forEach(function (area) {
                        $("#tenancyAreaName").append("<option value=" + area.tenancyAreaId + ">" + area.tenancyAreaName + "</option>");
                        form.render('select');
                    })
                });
            }

            //销售区域下拉框
            if(saleAreaId != "null"){
                //发送post请求，获取所有区域信息,并自动显示已选区域
                $.post('/broker-building/getSaleArea', function (info) {
                    //遍历循环部门信息
                    info.data.forEach(function (area) {
                        $("#saleAreaName").append("<option value=" + area.saleAreaId + ">" + area.saleAreaName + "</option>");
                        form.render('select');
                        $("#saleAreaName").val(saleAreaId);
                        form.render('select');
                    })
                });
            }else {
                //发送post请求，获取所有区域信息
                $.post('/broker-building/getSaleArea', function (info) {
                    //遍历循环部门信息
                    info.data.forEach(function (area) {
                        $("#saleAreaName").append("<option value=" + area.saleAreaId + ">" + area.saleAreaName + "</option>");
                        form.render('select');
                    })
                });
            }

        });
    });

});
